package com.zdxlz.fcmp.common.security.util;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequestWrapper;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description：全局请求参数包装类
 * @Author： aman
 * @Date： 2025/2/12 14:11
 */
public class GlobalHttpServletRequestWrapper extends HttpServletRequestWrapper {

    /**
     * 定义参数
     */
    private Map<String, String[]> parameterMaps;

    /**
     * @param request
     */
    public GlobalHttpServletRequestWrapper(HttpServletRequest request) {
        super(request);
        parameterMaps = new HashMap<>(request.getParameterMap());
    }

    @Override
    public String[] getParameterValues(String name) {
        String[] values = parameterMaps.get(name);
        if (values == null) {
            values = super.getParameterValues(name);
        }
        return values;
    }

    /**
     * 设置参数
     * @param name
     * @param value
     */
    public void setParameter(String name, String... value) {
        parameterMaps.put(name, value);
    }
}
